class Matrix:
    data = []
    width = 0
    height = 0

    def initWithMatrix(self, matrix):
        self.receive_width_and_height(matrix)
        self.data = matrix

    def initWithSizes(self, i, j):
        self.data = []

        ci = 0
        while ci < i:
            new_item = []

            cj = 0
            while cj < j:
                new_item.append(0.)
                cj = cj + 1

            self.data.append(new_item)
            ci = ci + 1

    def get(self, i, j):
        return self.data[i][j]

    def set(self, i, j, value):
        self.data[i][j] = value

    def receive_width_and_height(self, matrix):
        current_height = len(matrix)
        current_width = len(matrix[0]) if (current_height > 0) else 0

        self.validate(matrix, current_height, current_width)

        self.height = current_height
        self.width = current_width

    def validate(self, matrix, height, width):
        if height > 0 and width == 0:
            raise RuntimeError('IncorrectMatrixException')

        if len(matrix) != height:
            raise RuntimeError('IncorrectMatrixException')

        for row in matrix:
            if len(row) != width:
                raise RuntimeError('IncorrectMatrixException')

    @staticmethod
    def multiply(matrix1, matrix2):
        if matrix1.width != matrix2.height:
            raise RuntimeError('MatrixMultiplicationException')

        new_matrix = Matrix()
        new_matrix.initWithSizes(matrix1.height, matrix2.width)

        i = 0
        while i < matrix1.height:
            j = 0
            while j < matrix2.width:
                current = 0.
                k = 0
                while k < matrix1.width:
                    current = current + matrix1.get(i, k) * matrix2.get(k, j)
                    k = k + 1

                new_matrix.set(i, j, current)
                j = j + 1
            i = i + 1

        return new_matrix
